# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'integration.ui'
#
# Created: Mon May 31 21:32:27 2010
#	  by: PyQt4 UI code generator 4.7.2
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
from core import processing as proc
from model import integration_peaks


class IntegrWidget(QtGui.QDialog):
	
	def __init__(self, parent =None):
		QtGui.QDialog.__init__(self, parent)
		self.parent = parent
		self.setupUi()
				
	def setupUi(self):
		
		self.setWindowFlags(QtCore.Qt.Window)
		
		self.resize(400, 150)
		self.verticalLayout = QtGui.QVBoxLayout(self)
		self.verticalLayout.setObjectName("verticalLayout")
		
		gb = QtGui.QGroupBox("Files options", self)
		vl = QtGui.QVBoxLayout()
		self.pushButton = QtGui.QPushButton(self)
		self.pushButton.setMaximumSize(QtCore.QSize(125, 16777215))
		font = QtGui.QFont()
		font.setPointSize(9)
		self.pushButton.setFont(font)
		self.pushButton.setObjectName("pushButton")
		vl.addWidget(self.pushButton)
		self.horizontalLayout_2 = QtGui.QHBoxLayout()
		self.horizontalLayout_2.setObjectName("horizontalLayout_2")
		self.label_2 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.label_2.setFont(font)
		self.label_2.setObjectName("label_2")
		self.horizontalLayout_2.addWidget(self.label_2)
		self.lineEdit = QtGui.QLineEdit(self)
		self.lineEdit.setObjectName("lineEdit")
		self.horizontalLayout_2.addWidget(self.lineEdit)
		spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
		self.horizontalLayout_2.addItem(spacerItem)
		vl.addLayout(self.horizontalLayout_2)
		gb.setLayout(vl)
		self.verticalLayout.addWidget(gb)
		
		
		gb_2 = QtGui.QGroupBox("XCMS Parameters", self)
		
		hl = QtGui.QHBoxLayout()
		
		vl_2 = QtGui.QVBoxLayout()
		self.label = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setItalic(True)
		font.setUnderline(True)
		self.label.setFont(font)
		self.label.setObjectName("label")
		vl_2.addWidget(self.label)
		
		
		self.gridLayout = QtGui.QGridLayout()
		self.gridLayout.setObjectName("gridLayout")
		self.label_3 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.matchedfiltered = QtGui.QCheckBox("Use MatchedFiltered Algorithm", self )
		self.matchedfiltered.setChecked(True)
		self.gridLayout.addWidget(self.matchedfiltered, 0, 0, 1, 1)
		self.label_3.setFont(font)
		self.label_3.setObjectName("label_3")
		self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
		self.lineEdit_2 = QtGui.QLineEdit(self)
		self.lineEdit_2.setMaximumSize(QtCore.QSize(150, 16777215))
		self.lineEdit_2.setObjectName("lineEdit_2")
		self.gridLayout.addWidget(self.lineEdit_2, 1, 1, 1, 1)
		self.label_4 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.label_4.setFont(font)
		self.label_4.setObjectName("label_4")
		self.gridLayout.addWidget(self.label_4, 1, 2, 1, 1)
		self.lineEdit_3 = QtGui.QLineEdit(self)
		self.lineEdit_3.setMaximumSize(QtCore.QSize(150, 16777215))
		self.lineEdit_3.setObjectName("lineEdit_3")
		self.gridLayout.addWidget(self.lineEdit_3, 1, 3, 1, 1)
		self.label_5 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.label_5.setFont(font)
		self.label_5.setObjectName("label_5")
		self.gridLayout.addWidget(self.label_5, 2, 0, 1, 1)
		self.label_6 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.label_6.setFont(font)
		self.label_6.setObjectName("label_6")
		self.gridLayout.addWidget(self.label_6, 2, 2, 1, 1)
		self.lineEdit_4 = QtGui.QLineEdit(self)
		self.lineEdit_4.setMaximumSize(QtCore.QSize(150, 16777215))
		self.lineEdit_4.setObjectName("lineEdit_4")
		self.gridLayout.addWidget(self.lineEdit_4, 2, 1, 1, 1)
		self.lineEdit_5 = QtGui.QLineEdit(self)
		self.lineEdit_5.setMaximumSize(QtCore.QSize(150, 150))
		self.lineEdit_5.setObjectName("lineEdit_5")
		self.gridLayout.addWidget(self.lineEdit_5, 2, 3, 1, 1)
		self.label_7 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.label_7.setFont(font)
		self.label_7.setObjectName("label_7")
		self.gridLayout.addWidget(self.label_7, 3, 0, 1, 1)
		self.label_8 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.label_8.setFont(font)
		self.label_8.setObjectName("label_8")
		self.gridLayout.addWidget(self.label_8, 3, 2, 1, 1)
		self.lineEdit_6 = QtGui.QLineEdit(self)
		self.lineEdit_6.setMaximumSize(QtCore.QSize(150, 16777215))
		self.lineEdit_6.setObjectName("lineEdit_6")
		self.gridLayout.addWidget(self.lineEdit_6, 3, 1, 1, 1)
		self.lineEdit_7 = QtGui.QLineEdit(self)
		self.lineEdit_7.setMaximumSize(QtCore.QSize(150, 16777215))
		self.lineEdit_7.setObjectName("lineEdit_7")
		self.gridLayout.addWidget(self.lineEdit_7, 3, 3, 1, 1)
		self.gridLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum), 4, 0, 1, 1)
		vl_2.addLayout(self.gridLayout)
		
		
		self.gridLayout_2 =QtGui.QGridLayout()
		self.centWave = QtGui.QCheckBox("Use CentWave Algorithm", self)
		self.gridLayout_2.addWidget(self.centWave, 0, 0, 1, 1)
		self.ppm = QtGui.QLabel("ppm :")
		self.gridLayout_2.addWidget(self.ppm, 1, 0, 1, 1)
		self.spinBox = QtGui.QSpinBox()
		self.gridLayout_2.addWidget(self.spinBox, 1, 1, 1, 1)
		self.peakwidth = QtGui.QLabel("peakWidth :")
		self.gridLayout_2.addWidget(self.peakwidth, 2, 0, 1, 1)
		self.spinBox_2 = QtGui.QSpinBox()
		self.gridLayout_2.addWidget(self.spinBox_2, 2, 1, 1, 1)
		self.snthresh = QtGui.QLabel("snthresh :")
		self.gridLayout_2.addWidget(self.snthresh, 3, 0, 1, 1)
		self.spinBox_3 = QtGui.QSpinBox()
		self.gridLayout_2.addWidget(self.spinBox_3, 3, 1, 1, 1)
		self.mzdiff = QtGui.QLabel("mzdiff :")
		self.gridLayout_2.addWidget(self.mzdiff, 1, 2, 1, 1)
		self.lineEdit_8 = QtGui.QLineEdit(self)
		self.gridLayout_2.addWidget(self.lineEdit_8, 1, 3, 1, 1)
		self.mzcenterfun = QtGui.QLabel("mzcenterfun:")
		self.gridLayout_2.addWidget(self.mzcenterfun, 2, 2, 1, 1)
		self.centerfun = QtGui.QComboBox(self)
		self.centerfun.addItems(["apex", "wmean", "wmeanapex3", "meanapex3"])
		self.gridLayout_2.addWidget(self.centerfun, 2, 3, 1, 1)
		self.scanrange = QtGui.QLabel("scanrange :")
		self.gridLayout_2.addWidget(self.scanrange, 3, 2, 1, 1)
		self.lineEdit_9 = QtGui.QLineEdit(self)
		self.gridLayout_2.addWidget(self.lineEdit_9, 3, 3, 1, 1)
		
		#self.verticalLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
		
		vl_2.addLayout(self.gridLayout_2)
		
		self.plot =QtGui.QCheckBox( "Plot with R results", self)
		vl_2.addWidget(self.plot)
		
		self.verticalLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
		
		self.label_9 = QtGui.QLabel(self)
		font = QtGui.QFont()
		font.setItalic(True)
		font.setUnderline(True)
		self.label_9.setFont(font)
		self.label_9.setObjectName("label_9")
		vl_2.addWidget(self.label_9)
		self.gridLayout_2 = QtGui.QGridLayout()
		self.gridLayout_2.setObjectName("gridLayout_2")
		self.radioButton = QtGui.QRadioButton(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.radioButton.setFont(font)
		self.radioButton.setObjectName("radioButton")
		self.gridLayout_2.addWidget(self.radioButton, 0, 0, 1, 1)
		self.radioButton_2 = QtGui.QRadioButton(self)
		font = QtGui.QFont()
		font.setPointSize(9)
		self.radioButton_2.setFont(font)
		self.radioButton_2.setObjectName("radioButton_2")
		self.gridLayout_2.addWidget(self.radioButton_2, 1, 0, 1, 1)
		vl_2.addLayout(self.gridLayout_2)
		gb_2.setLayout(vl_2)
		self.verticalLayout.addWidget(gb_2)
		
		self.verticalLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
		
		self.merging = QtGui.QCheckBox("Merging samples :")
		self.verticalLayout.addWidget(self.merging)
		self.lineEdit_10 = QtGui.QLineEdit()
		self.lineEdit_10.setEnabled(False)
		self.verticalLayout.addWidget(self.lineEdit_10)
		self.new_name = QtGui.QLabel("Please enter a new name :")
		self.verticalLayout.addWidget(self.new_name)
		self.lineEdit_11 = QtGui.QLineEdit()
		self.lineEdit_11.setEnabled(False)
		self.verticalLayout.addWidget(self.lineEdit_11)
		
		self.verticalLayout.addItem(QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum))
		
		self.buttonBox = QtGui.QDialogButtonBox(self)
		self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
		self.verticalLayout.addWidget(self.buttonBox)

		self.retranslateUi()
		"""
		CentWave not yet implemented
		"""
		self.enable_disable_centwave(False)
		self.centWave.setEnabled(False)
		QtCore.QMetaObject.connectSlotsByName(self)

	def retranslateUi(self):
		self.setWindowTitle(QtGui.QApplication.translate("Form", "Integration Parameters", None, QtGui.QApplication.UnicodeUTF8))
		self.pushButton.setText(QtGui.QApplication.translate("Form", "Get Visualized File", None, QtGui.QApplication.UnicodeUTF8))
		self.label_2.setText(QtGui.QApplication.translate("Form", "PathFiles :", None, QtGui.QApplication.UnicodeUTF8))
		self.label.setText(QtGui.QApplication.translate("Form", "XCMS Integration", None, QtGui.QApplication.UnicodeUTF8))
		self.label_3.setText(QtGui.QApplication.translate("Form", "Max Peak detected :", None, QtGui.QApplication.UnicodeUTF8))
		self.label_4.setText(QtGui.QApplication.translate("Form", "fwhm :", None, QtGui.QApplication.UnicodeUTF8))
		self.label_5.setText(QtGui.QApplication.translate("Form", "Step :", None, QtGui.QApplication.UnicodeUTF8))
		self.label_6.setText(QtGui.QApplication.translate("Form", "Steps :", None, QtGui.QApplication.UnicodeUTF8))
		self.label_7.setText(QtGui.QApplication.translate("Form", "mzdiff :", None, QtGui.QApplication.UnicodeUTF8))
		self.label_8.setText(QtGui.QApplication.translate("Form", "snthresh :", None, QtGui.QApplication.UnicodeUTF8))
		self.label_9.setText(QtGui.QApplication.translate("Form", "XCMS Alignement", None, QtGui.QApplication.UnicodeUTF8))
		self.radioButton.setText(QtGui.QApplication.translate("Form", "Align with linear method (\"loess method\")", None, QtGui.QApplication.UnicodeUTF8))
		self.radioButton_2.setText(QtGui.QApplication.translate("Form", "Align with non linear method (\"orbiwarp\")", None, QtGui.QApplication.UnicodeUTF8))

	def initializeValue (self):
		self.lineEdit_2.setText("20")
		self.lineEdit_3.setText("30")
		self.lineEdit_4.setText("0.1")       
		self.lineEdit_5.setText("2")
		self.lineEdit_6.setText("0.5")
		self.lineEdit_7.setText("10")

	def printing(self,lspl):
		line=""
		for index, filename in enumerate (lspl.getFiles()):
			if not index: 
				line += filename
			else :
				line += ";" +filename
		if self.lineEdit.text() == "":
			self.lineEdit.setText( line )
		else:
			self.lineEdit.setText(self.widget.lineEdit.text() + ", " + line)
		
	def enable_disable_centwave(self, boolean):
		self.spinBox.setEnabled(boolean)
		self.spinBox_2.setEnabled(boolean)
		self.spinBox_3.setEnabled(boolean)
		self.lineEdit_8.setEnabled(boolean)
		self.centerfun.setEnabled(boolean)
		self.lineEdit_9.setEnabled(boolean)
	
	def enable_disable_matchedfiltered(self, boolean):
		self.lineEdit_2.setEnabled(boolean)
		self.lineEdit_3.setEnabled(boolean)
		self.lineEdit_4.setEnabled(boolean)
		self.lineEdit_5.setEnabled(boolean)
		self.lineEdit_6.setEnabled(boolean)
		self.lineEdit_7.setEnabled(boolean)
